souper-ir
A library for manipulating Souper IR.
This crate provides AST types for parsing or generating Souper IR. It is a suitable building block either for writing a custom LHS extractor, or for translating learned optimizations into your own peephole optimizations pass.
AST
The AST type definitions and builders live in the souper_ir::ast
module.
Parsing Souper IR
When the parse
Cargo feature is enabled, the souper_ir::parse
module
contains functions for parsing Souper IR from a file or an in-memory string.
use Path;
// We provide a filename to get better error messages.
let filename = new;
let replacements = parse_replacements_str?;
Emitting Souper IR's Text Format
When the stringify
Cargo feature is enabled, then the
souper_ir::ast::Replacement
, souper_ir::ast::LeftHandSide
, and
souper_ir::ast::RightHandSide
types all implement std::fmt::Display
. The
Display
implementation writes the AST type out as Souper's text format.
use ast;
// Build this Souper left-hand side:
//
// %x:i32 = var
// %y = mul %x, 2
// infer %y
//
// We expect that Souper would be able to synthesize a right-hand side that
// does a left shift by one instead of a multiplication.
let mut lhs = default;
let x = lhs.assignment;
let y = lhs.assignment;
let lhs = lhs.finish;
// Now we can stringify the LHS (and then, presumably, give it to Souper)
// with `std::fmt::Display`:
use Write;
let mut file = create?;
write!?;